<?php
namespace Home\Controller;
class ImageController extends LoginController
{
    function index()
    {
        $img = M("Img");
        $top = $img->limit(20)->select();
        $arr = $img->where("sid=9")->limit(4)->select();
        $arr4 = $img->where("fid=8")->limit(4)->select();
        $this->assign('arr', $arr);
        $this->assign('arr4', $arr4);
        $this->getip();
        $this->assign('top',$top);
        $this->simg();
        $this->fimg();
        $this->display();

    }
    function layout(){
        $this->layout();
    }
    function detail()
    {
        $this->simg1();
        $this->jimg1();
        $this->fimg1();
        $img = M("Img");
        $sid = $_GET["sid"];
        $fid = $_GET["fid"];
        $block['sid']=$sid;
        $block['fid']=$fid;
        if($fid&&$sid){
            $num=$img->where($block)->count();
        }else if($fid){
            $num=$img->where("fid=$fid")->count();
        }else if($sid){
            $num=$img->where("sid=$sid")->count();
        }else{
            $num=$img->count();
        }


// 		3、规定每页显示的条数
        $pageSize=20;
// 		4、实例化分页类
        $pageOb=new \Think\Page($num,$pageSize);
// 		5、获取开始位置值
        $start=$pageOb->firstRow;
// 		6、获取分页结果
        $pageStr=$pageOb->show();
        if($fid&&$sid){
            $arr = $img->where($block)->limit("$start,$pageSize")->select();
        }else if($fid){
            $arr = $img->where("fid=$fid")->limit("$start,$pageSize")->select();
        }else if($sid){
            $arr = $img->where("sid=$sid")->limit("$start,$pageSize")->select();
        }else{
            $arr = $img->limit("$start,$pageSize")->select();
        }


        $this->assign('pageStr',$pageStr);
        $this->assign('arr', $arr);
        $this->assign('sid', $sid);
        $this->assign('fid', $fid);

        $this->getip();
        $this->display();
    }
    function style()
    {
            $this->simg1();
            $this->jimg1();
            $this->fimg1();
            $img = M("Img");
            $sid = $_GET["sid"];
            $fid = $_GET["fid"];
            if($sid){
                $num=$img->where("sid=$sid")->count();
            }else if($fid){
                $num=$img->where("fid=$fid")->count();
            }else{
                $num=$img->count();
            }
// 		3、规定每页显示的条数
            $pageSize=20;
// 		4、实例化分页类
            $pageOb=new \Think\Page($num,$pageSize);
// 		5、获取开始位置值
            $start=$pageOb->firstRow;
// 		6、获取分页结果
            $pageStr=$pageOb->show();
        if($fid){
            $arr = $img->where("fid=$fid")->limit("$start,$pageSize")->select();
            $dOb = M("Fimg");
            $daohang = $dOb->where("fid=$fid")->find();
            $this->assign('daohang',$daohang);
            }else{
                $arr = $img->limit("$start,$pageSize")->select();
            }
            $this->assign('pageStr',$pageStr);
            $this->assign('arr', $arr);
            $this->getip();
            $this->display();
    }
    function xiangxi()
    {
        $Ob = M("Img");
        $id=$_GET["id"];
        $arr = $Ob->where("id=$id")->find();
        $dOb = M("Simg");
        $sid=$arr["sid"];
        $fid=$arr["fid"];
        if($sid){
            $daohang = $dOb->where("sid=$sid")->find();
            $fenlei = $daohang["sname"];
        }else{
            $daohang = $dOb->where("fid=$fid")->find();
            $fenlei = $daohang["fname"];
        }
        $arr1 = $Ob->where("title")->limit(10)->select();
        $this->assign('fenlei',$fenlei);
        $this->assign("arr1",$arr1);
        $this->assign('arr', $arr);
        $this->getip();
        $this->display();
    }
    function simg()
    {
        $Ob = M("Simg");
        $arr1 = $Ob->limit(6)->select();
        $this->assign('arr1', $arr1);
    }
    function jimg()
    {
        $Ob = M("Jimg");
        $arr2 = $Ob->limit(6)->select();
        $this->assign('arr2', $arr2);
    }
    function fimg()
    {
        $Ob = M("Fimg");
        $arr3 = $Ob->limit(6)->select();
        $this->assign('arr3', $arr3);
    }
    function simg1()
    {
        $Ob = M("Simg");
        $arr1 = $Ob->select();
        $this->assign('arr1', $arr1);
    }
    function jimg1()
    {
        $Ob = M("Jimg");
        $arr2 = $Ob->select();
        $this->assign('arr2', $arr2);
    }
    function fimg1()
    {
        $Ob = M("Fimg");
        $arr3 = $Ob->select();
        $this->assign('arr3', $arr3);
    }
    function add()
    {
        $bjadd = M("Baojia");
        $addtime = time();
        $ip = get_client_ip();
        $re = $bjadd->data($_POST)->add();
        if ($re) {
            echo json_encode(array('msg' => 1));
        } else {
        }
    }
}